package com.leetcode.May;

import java.util.ArrayList;

/**
 * @Description: 力扣-两数之和
 * @Author: Mr.Fxy
 * @CreateTime: 2024-05-09 19:53
 */
public class SumOfTwoNumbers {
    public static void main(String[] args) {
        int[] ints = twoSum(new int[]{2, 7, 11, 15}, 9);
        for (int anInt : ints) {
            System.out.printf(String.valueOf(anInt));
        }
    }
    public static int[] twoSum(int[] nums, int target) {
        ArrayList<Integer> arrayList = new ArrayList<>();
        for (int i = 0; i < nums.length; i++) {
            for (int j = i + 1; j < nums.length; j++) {
                if (nums[i] + nums[j] == target) {
                    arrayList.add(i);
                    arrayList.add(j);
                }
            }
        }
        int[] intArray = new int[arrayList.size()];
        for (int i = 0; i < arrayList.size(); i++) {
            intArray[i] = arrayList.get(i);
        }
        return intArray;
    }
}
